import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/product',
    // children: [
    //   {
    //     path: 'dashboard',
    //     component: () => import('@/views/dashboard/index'),
    //     name: 'Dashboard',
    //     meta: { title: 'Dashboard', icon: 'dashboard', affix: true }
    //   }
    // ]
  },
  {
    path: '/product',
    component: Layout,
    name: 'product',
    meta: {
      title: 'product',
      icon: 'table'
    },
    children: [
      {
        path: '/product-list',
        component: () => import('@/views/product/index'),
        name: '产品中心',
        meta: { title: '产品中心' }
      },
      {
        path: '/add-product',
        component: () => import('@/views/product/add-product'),
        name: '新增产品',
        meta: { title: '新增产品', activeMenu: '/product' },
        hidden: true
      },
      {
        path: '/edit-product',
        component: () => import('@/views/product/add-product'),
        name: '编辑产品',
        meta: { title: '编辑产品', activeMenu: '/product' },
        hidden: true
      },
      {
        path: '/product-detail',
        component: () => import('@/views/product/add-product'),
        name: '产品详情',
        meta: { title: '产品详情', activeMenu: '/product-detail' },
        hidden: true
      }
    ]
  },
  {
    path: '/pages',
    component: Layout,
    name: 'pages',
    meta: {
      title: 'pages',
      icon: 'table'
    },
    children: [
      {
        path: '/pages',
        component: () => import('@/views/pages/index'),
        name: '页面',
        meta: { title: '页面' }
      },
      {
        path: '/add-page',
        component: () => import('@/views/pages/add-page'),
        name: '新增页面',
        meta: { title: '新增页面', activeMenu: '/pages' },
        hidden: true
      },
      {
        path: '/edit-page',
        component: () => import('@/views/pages/add-page'),
        name: '编辑页面',
        meta: { title: '编辑页面', activeMenu: '/pages' },
        hidden: true
      },
      {
        path: '/detail-page',
        component: () => import('@/views/pages/add-page'),
        name: '页面详情',
        meta: { title: '页面详情', activeMenu: '/pages' },
        hidden: true
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'Profile', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/news',
    component: Layout,
    name: 'news',
    meta: {
      title: 'news',
      icon: 'table'
    },
    children: [
      {
        path: '/news',
        component: () => import('@/views/news/index'),
        name: '新闻',
        meta: { title: '新闻' }
      },
      {
        path: '/add-new',
        component: () => import('@/views/news/add-new'),
        name: '新增新闻',
        meta: { title: '新增新闻', activeMenu: '/news' },
        hidden: true
      },
      {
        path: '/edit-new',
        component: () => import('@/views/news/add-new'),
        name: '编辑新闻',
        meta: { title: '编辑新闻', activeMenu: '/news' },
        hidden: true
      },
      {
        path: '/detail-new',
        component: () => import('@/views/news/add-new'),
        name: '新闻详情',
        meta: { title: '新闻详情', activeMenu: '/news' },
        hidden: true
      },
    ]
  },
  {
    path: '/keywords',
    component: Layout,
    name: 'keywords',
    meta: {
      title: 'keywords',
      icon: 'table'
    },
    children: [
      {
        path: '/keywords',
        component: () => import('@/views/keywords/index'),
        name: '关键词管理',
        meta: { title: '关键词管理' }
      }
    ]
  },
  {
    path: '/media',
    component: Layout,
    name: 'media',
    meta: {
      title: 'media',
      icon: 'table'
    },
    children: [
      {
        path: '/media',
        component: () => import('@/views/media/index'),
        name: '媒体库',
        meta: { title: '媒体库' }
      },
      {
        path: '/add-media',
        component: () => import('@/views/media/add-media'),
        name: '新增媒体库',
        meta: { title: '新增媒体库', activeMenu: '/media' },
        hidden: true
      },
      {
        path: '/edit-media',
        component: () => import('@/views/media/add-media'),
        name: '编辑媒体库',
        meta: { title: '编辑媒体库', activeMenu: '/media' },
        hidden: true
      },
      {
        path: '/detail-media',
        component: () => import('@/views/media/add-media'),
        name: '媒体库详情',
        meta: { title: '媒体库详情', activeMenu: '/media' },
        hidden: true
      },
    ]
  },
  {
    path: '/download',
    component: Layout,
    name: 'download',
    meta: {
      title: 'download',
      icon: 'table'
    },
    children: [
      {
        path: '/download',
        component: () => import('@/views/download/index'),
        name: '下载中心',
        meta: { title: '下载中心' }
      },
      {
        path: '/add-download',
        component: () => import('@/views/download/add-download'),
        name: '新增下载中心',
        meta: { title: '新增下载中心', activeMenu: '/download' },
        hidden: true
      },
      {
        path: '/edit-download',
        component: () => import('@/views/download/add-download'),
        name: '编辑下载',
        meta: { title: '编辑下载', activeMenu: '/download' },
        hidden: true
      },
      {
        path: '/detail-download',
        component: () => import('@/views/download/add-download'),
        name: '下载详情',
        meta: { title: '下载详情', activeMenu: '/download' },
        hidden: true
      },
    ]
  },
  {
    path: '/cate',
    component: Layout,
    name: 'cate',
    meta: {
      title: 'cate',
      icon: 'table'
    },
    children: [
      {
        path: '/cate',
        component: () => import('@/views/cate/index'),
        name: '类型管理',
        meta: { title: '类型管理' }
      }
    ]
  },


]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
